<!-- /*
 * @Author: RDSunday 
 * @Date: 2020-03-17 10:23:55 
 * @Last Modified by:   RDSunday 
 * @Last Modified time: 2020-03-17 10:23:55 
 */ -->
 <!-- 判断是移动浏览器还是pc端浏览器 -->
 <!-- 判断是否是微信浏览器 -->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <p>JavaScript判断当前设备是移动端还是PC端浏览器</p>
    <p>JavaScript 判断是否在微信浏览器中打开</p>
    <br>
    <script>
        // navigator.userAgent区分设备和浏览器
        // test(string)如果string中含有与RegExpObject匹配的文本返回true,否则返回false
        if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
            document.writeln("移动")
        } else {
            document.writeln("PC" + "<br>")
        }
        function is_weixn() {
            var ua = navigator.userAgent.toLowerCase();
            if(ua.match(/MicroMessenger/i)=="micromessenger") {
                return true;
            }
            else {
                return false;
            }

        }
        if(is_weixn()) {
            document.writeln("微信浏览器");

        }else {
            document.writeln("其他浏览器");   
        }
    </script>
</body>
</html>